// pages/unloadgoods/unloadgoods.js
const app = getApp();
Page({
  data: {
    orderid: ''
  },
  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    var orderid = options.orderid;
    that.setData({
      orderid: orderid,
    })

  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },

  formSubmit: function (e) {
    let that = this;
    let date = new Date();
    let numberL = e.detail.value.numberL;
    let volumeL = e.detail.value.volumeL;
    let weightL = e.detail.value.weightL;
    let fmtDate = that.fromDate(date, 'yyyy-MM-dd hh:mm:ss');
    let orderid = that.data.orderid;
    wx.request({
      url: 'http://47.111.122.217:9001/transport/transportProcess/update/xiehuo',
      method: 'put',
      data: {
        "id": orderid,
        "trueEndTime": fmtDate,
        "trueNumber": numberL,
        "trueXVolume": volumeL,
        "trueXWeight": weightL
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        if (res.data.success) {
          wx.showToast({
            title: '装货成功',
            icon: 'success',
            duration: 2000
          }),
          wx.navigateTo({
            url: '../order/order',
          })
        } else {
          return false;
        }
      }
    })
  },
  //日期转换
  fromDate: function (date, fmt) {
    var that = this;
    date = new Date(date)
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length))
    }

    let obj = {
      "M+": date.getMonth() + 1,
      "d+": date.getDay(),
      "h+": date.getHours(),
      "m+": date.getMinutes(),
      "s+": date.getSeconds()
    }

    for (let key in obj) {
      if (new RegExp(`(${key})`).test(fmt)) {
        let str = obj[key] + ''
        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : that.padLeftZero(str))
      }
    }
    return fmt
  },
  padLeftZero: function (str) {
    return ('00' + str).substr(str.length)
  },
})